//https://leetcode.cn/problems/implement-rand10-using-rand7/
#include <cstdlib>
// The rand7() API is already defined for you.
// int rand7();
// @return a random integer in the range 1 to 7

class Solution {
public:
    int rand10() {
        int ans = 0;
        do {
            ans = ((rand7() - 1) * 7 + rand7());
        } while (ans > 40);
        return 1 + ans % 10;
    }
};



//rand3实现rand5
// 假设 rand3() 已经定义好
int rand3() {
    return rand() % 3 + 1;
}

int rand5() {
    int a, b, num;
    do {
        a = rand3();
        b = rand3();
        num = (a - 1) * 3 + b; // 生成 [1, 9] 范围内的均等随机数
    } while (num > 5); // 只接受 [1, 5] 范围内的数
    return num;
}
